<html>
<head><meta charset="utf-8"><title>Find the name of a crate before I know the edition? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html">Find the name of a crate before I know the edition?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="208408998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/208408998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#208408998">(Aug 29 2020 at 00:58)</a>:</h4>
<p>I'm starting to think the answer is no but ... for <a href="#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Require.20users.20to.20confirm.20they.20know.20RUSTC_.E2.80.A6.20compiler-team.23350/near/208403962">https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Require.20users.20to.20confirm.20they.20know.20RUSTC_.E2.80.A6.20compiler-team.23350/near/208403962</a> I want to find the name of the crate before calling <code>is_nightly_build()</code>. However I have no idea how to do this before the <code>Queries</code> are created. Is this possible even in theory?</p>



<a name="208409093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/208409093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#208409093">(Aug 29 2020 at 01:00)</a>:</h4>
<p>some places this pops up:</p>
<div class="codehilite"><pre><span></span><code><span class="n">src</span><span class="o">/</span><span class="n">librustc_driver</span><span class="o">/</span><span class="n">lib</span><span class="p">.</span><span class="n">rs</span><span class="w"></span>
<span class="mi">696</span>:                        <span class="nc">UnstableFeatures</span>::<span class="n">from_environment</span><span class="p">().</span><span class="n">is_nightly_build</span><span class="p">();</span><span class="w"></span>
<span class="mi">783</span>:    <span class="nc">let</span><span class="w"> </span><span class="n">nightly_help</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">nightly_options</span>::<span class="n">is_nightly_build</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="mi">793</span>:    <span class="nc">let</span><span class="w"> </span><span class="n">at_path</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">verbose</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="n">nightly_options</span>::<span class="n">is_nightly_build</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>

<span class="n">src</span><span class="o">/</span><span class="n">librustc_session</span><span class="o">/</span><span class="n">config</span><span class="p">.</span><span class="n">rs</span><span class="w"></span>
<span class="mi">1211</span>:    <span class="nc">if</span><span class="w"> </span><span class="o">!</span><span class="n">edition</span><span class="p">.</span><span class="n">is_stable</span><span class="p">()</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="o">!</span><span class="n">nightly_options</span>::<span class="n">is_nightly_build</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="mi">1508</span>:            <span class="nc">if</span><span class="w"> </span><span class="n">kind</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">NativeLibKind</span>::<span class="n">StaticNoBundle</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="o">!</span><span class="n">nightly_options</span>::<span class="n">is_nightly_build</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="mi">1925</span>:        <span class="nc">is_nightly_build</span><span class="p">()</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="n">matches</span><span class="p">.</span><span class="n">opt_strs</span><span class="p">(</span><span class="s">&quot;Z&quot;</span><span class="p">).</span><span class="n">iter</span><span class="p">().</span><span class="n">any</span><span class="p">(</span><span class="o">|</span><span class="n">x</span><span class="o">|</span><span class="w"> </span><span class="o">*</span><span class="n">x</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s">&quot;unstable-options&quot;</span><span class="p">)</span><span class="w"></span>
<span class="mi">1928</span>:    <span class="nc">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">is_nightly_build</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="kt">bool</span> <span class="p">{</span><span class="w"></span>
<span class="mi">1929</span>:        <span class="nc">UnstableFeatures</span>::<span class="n">from_environment</span><span class="p">().</span><span class="n">is_nightly_build</span><span class="p">()</span><span class="w"></span>
<span class="mi">1935</span>:            <span class="nc">UnstableFeatures</span>::<span class="n">from_environment</span><span class="p">().</span><span class="n">is_nightly_build</span><span class="p">();</span><span class="w"></span>

<span class="n">src</span><span class="o">/</span><span class="n">librustc_session</span><span class="o">/</span><span class="n">parse</span><span class="p">.</span><span class="n">rs</span><span class="w"></span>
<span class="mi">110</span>:    <span class="nc">if</span><span class="w"> </span><span class="n">sess</span><span class="p">.</span><span class="n">unstable_features</span><span class="p">.</span><span class="n">is_nightly_build</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
</code></pre></div>



<a name="209305044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305044">(Sep 07 2020 at 15:04)</a>:</h4>
<p>FYI <span class="user-mention" data-user-id="239881">@Josh Triplett</span> I haven't forgotten about <code>RUSTC_BOOTSTRAP=crate</code>, it's blocked on this</p>



<a name="209305079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305079">(Sep 07 2020 at 15:04)</a>:</h4>
<p>didn't find time to work on it last weekend</p>



<a name="209305115"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305115" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305115">(Sep 07 2020 at 15:04)</a>:</h4>
<p>No problem. Thank you!</p>



<a name="209305181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305181">(Sep 07 2020 at 15:05)</a>:</h4>
<p>Edition <em>must</em> be specified on CLI, unlike crate name which is both in CLI and attributes.</p>



<a name="209305269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305269">(Sep 07 2020 at 15:05)</a>:</h4>
<p>ok, so in theory this should be possible</p>



<a name="209305335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305335">(Sep 07 2020 at 15:06)</a>:</h4>
<p>I would look for where Session is constructed -- at that point we've definitely parsed cli args</p>



<a name="209305393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305393">(Sep 07 2020 at 15:06)</a>:</h4>
<p>Perhaps an easier solution -- and equally fine, IMO, is to always have UnstableFeatures return "true" if RUSTC_BOOTSTRAP is set at all</p>



<a name="209305406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305406">(Sep 07 2020 at 15:07)</a>:</h4>
<p>and then have a hard error as early as possible if crate isn't in it</p>



<a name="209305439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305439">(Sep 07 2020 at 15:07)</a>:</h4>
<p>I don't understand the proposed solution - most places that call <code>is_nightly_build()</code> never do anything with <code>UnstableFeatures</code> after</p>



<a name="209305498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305498">(Sep 07 2020 at 15:08)</a>:</h4>
<p>so if that returns true, it's as if they set RUSTC_BOOTSTRAP to 1, there's no place to check the crate name</p>



<a name="209305536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305536">(Sep 07 2020 at 15:08)</a>:</h4>
<p>I'm just saying you'd do that e.g. as part of session construction</p>



<a name="209305560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305560">(Sep 07 2020 at 15:08)</a>:</h4>
<p>oh I see what you mean</p>



<a name="209305569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305569">(Sep 07 2020 at 15:08)</a>:</h4>
<p>oh I guess that wouldn't help</p>



<a name="209305576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305576">(Sep 07 2020 at 15:08)</a>:</h4>
<p>because we don't want to fatal error</p>



<a name="209305579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305579">(Sep 07 2020 at 15:08)</a>:</h4>
<p>yeah part of the issue is that this doesn't always go through <code>Session</code></p>



<a name="209305581"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305581" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305581">(Sep 07 2020 at 15:09)</a>:</h4>
<p>hm</p>



<a name="209305732"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305732" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305732">(Sep 07 2020 at 15:10)</a>:</h4>
<p>you're probably going to have to try and remove the unstable_features from e.g. ParseSess</p>



<a name="209305765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305765">(Sep 07 2020 at 15:10)</a>:</h4>
<p>crate_name being possible to set in code makes this annoying</p>



<a name="209305805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305805">(Sep 07 2020 at 15:11)</a>:</h4>
<p>we could just ignore that case and not work with it, since it's atypical, but that seems bad</p>



<a name="209305861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305861">(Sep 07 2020 at 15:11)</a>:</h4>
<p>Using RUSTC_BOOTSTRAP is also atypical. :)</p>



<a name="209305994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209305994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209305994">(Sep 07 2020 at 15:12)</a>:</h4>
<p>Doesn't seem too unreasonable to need to use the declared name of your crate from Cargo.toml rather than a name you declared from a .rs file.</p>



<a name="209306055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209306055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209306055">(Sep 07 2020 at 15:13)</a>:</h4>
<p>As long as we handle the dash-vs-underscore thing.</p>



<a name="209306066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209306066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209306066">(Sep 07 2020 at 15:13)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F/near/209305994">said</a>:</p>
<blockquote>
<p>Doesn't seem too unreasonable to need to use the declared name of your crate from Cargo.toml rather than a name you declared from a .rs file.</p>
</blockquote>
<p>I don't like the idea of breaking stable code for this though</p>



<a name="209306082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209306082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209306082">(Sep 07 2020 at 15:13)</a>:</h4>
<p>er, well, it wouldn't?</p>



<a name="209306141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209306141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209306141">(Sep 07 2020 at 15:14)</a>:</h4>
<p>we just wouldn't enable unstable features which is <em>by definition</em> not breaking stable code</p>



<a name="209306156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209306156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209306156">(Sep 07 2020 at 15:14)</a>:</h4>
<p>I like the idea of '<code>RUSTC_BOOTSTRAP=crate</code> works only sometimes' even less :/</p>



<a name="209306166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209306166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209306166">(Sep 07 2020 at 15:14)</a>:</h4>
<p>it works <em>always</em> if you specify --crate-name on the CLI</p>



<a name="209306181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209306181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209306181">(Sep 07 2020 at 15:14)</a>:</h4>
<p>which Cargo always does</p>



<a name="209306218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209306218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209306218">(Sep 07 2020 at 15:15)</a>:</h4>
<p>hmm</p>



<a name="209306242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209306242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209306242">(Sep 07 2020 at 15:15)</a>:</h4>
<p>One question -- do we know what the crate name for something like <code>rustc foo.rs</code> is? <code>foo</code>?</p>



<a name="209306251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209306251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209306251">(Sep 07 2020 at 15:15)</a>:</h4>
<p>well, I'll see how hard it is to implement and if it turns out to be a pain I can ignore <code>#![crate_name]</code> like you suggest</p>



<a name="209306265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209306265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209306265">(Sep 07 2020 at 15:15)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F/near/209306242">said</a>:</p>
<blockquote>
<p>One question -- do we know what the crate name for something like <code>rustc foo.rs</code> is? <code>foo</code>?</p>
</blockquote>
<p>that's what I would expect</p>



<a name="209306355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209306355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209306355">(Sep 07 2020 at 15:16)</a>:</h4>
<p>My guess is that you want to modify UnstableFeatures::from_environment to take a crate name, and then try and push it down as needed to support that</p>



<a name="209306371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/209306371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#209306371">(Sep 07 2020 at 15:16)</a>:</h4>
<p>we do some early parsing of crate-level attributes already IIRC</p>



<a name="212924900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/212924900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#212924900">(Oct 10 2020 at 17:04)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F/near/209305732">said</a>:</p>
<blockquote>
<p>you're probably going to have to try and remove the unstable_features from e.g. ParseSess</p>
</blockquote>
<p>this is actually really easy surprisingly</p>
<div class="codehilite"><pre><span></span><code>(-bash@build-server) ~/rustc ▶️ rg &#39;sess.unstable_features&#39; compiler/
compiler/rustc_session/src/parse.rs
109:    if sess.unstable_features.is_nightly_build() {

compiler/rustc_parse/src/parser/diagnostics.rs
417:            let allow_unstable = self.sess.unstable_features.is_nightly_build();
</code></pre></div>



<a name="212925525"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/212925525" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#212925525">(Oct 10 2020 at 17:11)</a>:</h4>
<p>well, I take that back, this function wants to know about the release channel but doesn't take a crate name (and taking one would be pretty invasive):</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="sd">/// Construct a diagnostic for a feature gate error.</span>
<span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">feature_err_issue</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="p">(</span><span class="w"></span>
<span class="w">    </span><span class="n">sess</span>: <span class="kp">&amp;</span><span class="o">'</span><span class="na">a</span> <span class="nc">ParseSess</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">feature</span>: <span class="nc">Symbol</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">span</span>: <span class="nc">impl</span><span class="w"> </span><span class="nb">Into</span><span class="o">&lt;</span><span class="n">MultiSpan</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">issue</span>: <span class="nc">GateIssue</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">explain</span>: <span class="kp">&amp;</span><span class="kt">str</span><span class="p">,</span><span class="w"></span>
<span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">DiagnosticBuilder</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
</code></pre></div>



<a name="212925726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/212925726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#212925726">(Oct 10 2020 at 17:15)</a>:</h4>
<p>ok so my current plan is to only support <code>--crate-name</code> and anything using <code>#![crate_name]</code> will still have to use <code>RUSTC_BOOTSTRAP=1</code></p>



<a name="212925918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/212925918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#212925918">(Oct 10 2020 at 17:18)</a>:</h4>
<p>actually this works well because the use case is cargo build scripts</p>



<a name="212925922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/212925922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#212925922">(Oct 10 2020 at 17:18)</a>:</h4>
<p>so --crate-name will <em>always</em> be set in the cases when <code>RUSTC_BOOTSTRAP=1</code> is disallowed</p>



<a name="212929994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Find%20the%20name%20of%20a%20crate%20before%20I%20know%20the%20edition%3F/near/212929994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Find.20the.20name.20of.20a.20crate.20before.20I.20know.20the.20edition.3F.html#212929994">(Oct 10 2020 at 19:01)</a>:</h4>
<p>opened <a href="https://github.com/rust-lang/rust/pull/77802">https://github.com/rust-lang/rust/pull/77802</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>